package com.mk.cloud.pt.controller.app;

import act.apidoc.Description;
import act.controller.Controller;
import act.handler.NonBlock;
import act.inject.DefaultValue;
import act.util.CacheFor;
import com.mk.cloud.common.domain.PCompany;
import com.mk.cloud.common.domain.PWechatMenus;
import com.mk.cloud.common.enums.GlobalValues;
import com.mk.cloud.common.interceptor.header.HeaderService;
import com.mk.cloud.common.interceptor.header.IHLogin;
import com.mk.cloud.common.util.ResUtils;
import com.mk.cloud.pt.service.app.PCompanyService;
import org.beetl.sql.core.engine.PageQuery;
import org.osgl.http.H;
import org.osgl.mvc.annotation.GetAction;
import org.osgl.mvc.annotation.With;
import org.osgl.util.S;

import javax.inject.Inject;
import java.util.HashMap;
import java.util.Map;

@Controller("app/wechatMenus")
public class PWechatMenusController extends HeaderService {

    @Inject
    private PWechatMenus.Mapper pWechatMenusMapper;

    @Inject
    private PCompanyService pCompanyService;

    @Description("小程序动态菜单--小程序动态菜单列表")
    @GetAction("list.json")
    @CacheFor(value = 10 * 60)
    @NonBlock
    public String pProductList(
            @Description("小程序的appid") String appid,
            @Description("展示位置") @DefaultValue("0") String showplace,
            @Description("当前第几页") @DefaultValue("1") Integer currentPage,
            @Description("每页多少条") @DefaultValue("100") Integer pageSize

    ) {
        PageQuery<PWechatMenus> query = new PageQuery<>();
        query.setPageSize(pageSize);
        query.setPageNumber(currentPage);
        Map<String, Object> map = new HashMap<>();
        map.put("isshow", GlobalValues.FLAG_YES.value());
        map.put("showplace", showplace);
        map.put("coid", pCompanyService.getCompanyByAppid(appid).getCoid());
        query.setParas(map);
        //此处的sql是三个sql
        pWechatMenusMapper.getSQLManager().pageQuery("pWechatMenus.select_wechat_menus_list", PWechatMenus.class, query);
        return ResUtils.OK(query.getList());
    }


    @Description("小程序动态菜单--小程序动态菜单详情")
    @GetAction("get.json")
    @CacheFor(value = 10 * 60)
    @NonBlock
    public String getPWechatMenus(@Description("小程序动态菜单id") String sid) {
        if (S.isEmpty(sid)) {
            return ResUtils.OK(new PWechatMenus());
        }
        return ResUtils.OK(pWechatMenusMapper.single(sid));
    }

}
